/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            workDeductionInfo: {
                works: [],
                states: [
                    {
                        name: '全部',
                        state: ''
                    }, {
                        name: '待处理',
                        state: 'W'
                    }, {
                        name: '处理完成',
                        state: 'C'
                    }, {
                        name: '超时工作单',
                        state: 'timeout'
                    }
                ],
                total: 0,
                records: 1,
                moreCondition: false,
                wtId: '',
                conditions: {
                    staffNameLike: '',
                    deductionPersonNameLike: '',
                    communityId: ''
                }
            }
        },
        _initMethod: function () {
            $that._listWorkDeductions(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('workDeduction', 'listWorkDeduction', function (_param) {
                $that._listWorkDeductions(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listWorkDeductions(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listWorkDeductions: function (_page, _rows) {
                $that.workDeductionInfo.conditions.page = _page;
                $that.workDeductionInfo.conditions.row = _rows;
                $that.workDeductionInfo.conditions.communityId = vc.getCurrentCommunity().communityId;
                let param = {
                    params: $that.workDeductionInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/work.listWorkDeduction',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.workDeductionInfo.total = _json.total;
                        $that.workDeductionInfo.records = _json.records;
                        $that.workDeductionInfo.works = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.workDeductionInfo.records,
                            dataCount: $that.workDeductionInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _toWorkDetailPage: function (_work) {
                vc.jumpToPage('/#/pages/oa/workDetail?workId=' + _work.workId);
            },
            _queryWorkDeductionMethod: function () {
                $that._listWorkDeductions(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _resetWorkDeductionMethod: function () {
                vc.component.workDeductionInfo.conditions.workNameLike = "";
                vc.component.workDeductionInfo.conditions.createUserNameLike = "";
                vc.component.workDeductionInfo.conditions.staffNameLike = "";
                vc.component.workDeductionInfo.conditions.queryStartTime = "";
                vc.component.workDeductionInfo.conditions.queryEndTime = "";
                $that._listWorkDeductions(DEFAULT_PAGE, DEFAULT_ROWS);
            },
        }
    });
})(window.vc);
